<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>老师端提问列表</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css">
	
		<link rel="stylesheet" href="../../css/weui.min.css">
    <style>
		body {

		}
	.mui-table-view-cell>a:not(.mui-btn){
    		padding: 10px;
    	}
    	.cell-title{
    		height: 22px;
    	}
    	.cell-subtitle,.message_content{
    		height: 20px;
    	}
    	.right-div{
    		width: 70px;
    		float: right;
    	}
    	.left-div{
    		margin-right: 70px;
    	}
    	.message_title{
    		width: 90%;
    	}
    	.right-tag{
    		text-align: right;
    	}
    	.mui-table-view .mui-media-object{
    		margin-top: 10px;
    	}
    	.discuss-del{
    		width:28px;
    		margin-right: 0px;
    	}
    	.discuss-del-div{
    		text-align: right;
	         height: 20px;
    	}
    		.popu_img {
				height: 20px;
				width: 20px;
			}
    </style>
</head>
<body>

  <div id="mian">
	
		
		<ul id="questionsList" class="mui-table-view">

	<!--<li class="mui-table-view-cell mui-media">
			<a href="javascript:;">
				<img class="mui-media-object mui-pull-left" src="../../image/icon_taolun1.png"  style="margin-top: 0px">
				<div class="mui-media-body">
					<div class="right-div">
						<div class="discuss-del-div">
							<img src="../../image/icon_bewrite_down.png" class="discuss-del">
						</div>
						<p class="mui-ellipsis base_grey content_p right-tag">
							未参与
						</p>
					</div>
					<div class="left-div">
						<p class="mui-ellipsis base_dark_grey font16 cell-title">
							<span class="message_title">
								讨论名称
							</span>  
						</p>
					
						<p class="mui-ellipsis base_grey font14 content_p cell-subtitle">
							<span class="file_submit_time">
								2017-01-02 14:20
							</span>
						</p>
					</div>
				</div>
			</a>
		</li>-->
	
	</ul>

</div>
	<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button"  onclick="loadNewData()"class="mui-btn mui-btn-outlined">
				重新加载
			</button>
		</div>
						<!--删除微博-->
	<div id="logout" class="weui_dialog_confirm" style="display: none;">
		<div class="weui_mask"></div>
	    <div class="weui_dialog">
	        <div class="weui_dialog_hd"><strong class="weui_dialog_title">是否确定删除提问？</strong></div>
	        
	        <div class="weui_dialog_ft">
	            <a href="javascript:cancel();" class="weui_btn_dialog default" style="color:#18b4ed">取消</a>
	            <a  href="javascript:confirm();" class="weui_btn_dialog primary" style="color:#18b4ed">确定</a>
	        </div>
	    </div>
	</div>
</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/activityBottomPopup.js"></script>
 <script type="text/javascript">
	var page = 1;
	var row = 10;
	var refreshCount = 0;
	var  tid='';
	apiready = function(){
	    showProgress();
		loadNewData();
		setRefreshHeader();
		setPullUpRefresh();
		api.addEventListener({
	        name:'refreshQusetionData'
        },function(ret,err){
        	//coding...
        	loadNewData();
        });
        //老师端是否有更新
        api.addEventListener({
	        name:'pushMessage_classroomMessage'
        },function(ret,err){
        	//coding...
        if(TW_TYPE == ret.value.type && $api.getStorage('cfnetppjxid') == ret.value.jid&& $api.getStorage('cfnetppuid')== ret.value.uid){
        	loadNewData();
        	}
        });
        sendBuriedNotifi('0', '老师端提问列表页', '201')
	};
    function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

	//获取数据
	function loadData() {	

	    
		var params = {
			jid : $api.getStorage('cfnetppjxid'),
			uid:$api.getStorage('cfnetppuid'),
			tid:2,
            page:page,
            rows: row,
            cid : api.pageParam.cid,
            pid : api.pageParam.pid,
		};
//alert(JSON.stringify(data));
		cfnetppPOST(url_activeList, params, true, function(data, status) {
//		alert(JSON.stringify(data));
			api.hideProgress();
			api.refreshHeaderLoadDone();
			if (status == 'success') {
				if (data.code == 200) {
					var listdata = data.data;
					if (listdata != '' && listdata.constructor == Array && listdata.length > 0) {
						$('#noData').hide();
						$('#noNet').hide();
						$('#mian').show();
						refreshCount = listdata.length;
						writelist(listdata,refreshCount);
					} else {
					 if(page ==1){
						$('#noData').show();
						$('#noNet').hide();
						}

					}
				} else if (data.code = 109) {
				  if(page ==1){
					$('#noData').show();
					$('#noNet').hide();
					$('#mian').hide();
					}

				} else {
				if(page ==1){
					$('#noData').show();
					$('#noNet').hide();
					$('#mian').hide();
					}

				}
			} else {
				$('#noData').hide();
				$('#noNet').show();
			   $('#mian').hide();

			}
		});
	}
		function writelist(listdata,len){
		   var htmlsdata='';
		   for(var i=0;i<len;i++){
		     var data = listdata[i];
		     var type =data.status;
		     var delethtml='';
		     var status = ''; 
		     	var DataArr = JSON.stringify(data).replace(/"/g, '&quot;');
		   if (type == 0) {//未开始
				status = '未开始';
				delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
			} else if (type == 1) {//进行中
				status = '进行中';
				delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';

			}else if(type == 2){//结束
			    status = '已结束';
			delethtml="<span class='base_grey font12'>"+data.num+'/'+data.countnum+"提问</span>";
			
			}
			 var classname = '';
		     if (data.classname == "" || data.classname == null) {
		     	classname = '';
		     }else{
		     	classname = data.classname;
		     }
	       var htmls='<li class="mui-table-view-cell mui-media" id='+data.id+' onclick="openwin1('+data.id+','+"'"+data.name+"'"+','+type+')">'+
			'<a href="javascript:;">'+
				'<img class="mui-media-object mui-pull-left" src="../../image/inco_qusetion.png" style="margin-top: 0px">'+
				'<div class="mui-media-body">'+
					'<div class="right-div">'+
						'<div class="discuss-del-div">'+
							delethtml+
						'</div>'+
						'<p class="mui-ellipsis base_grey content_p right-tag font12">'+
						 status+
						'</p>'+
					'</div>'+
					'<div class="left-div">'+
						'<p class="mui-ellipsis base_black_grey font14 cell-title">'+
						'<span class="message_title ">'+
							data.name+
							'</span>  '+
						'</p>'+
						
						'<p class="mui-ellipsis base_grey font12 content_p cell-subtitle">'+
							'<span class="file_submit_time">'+
									timeWithStamp3(data.createtime)+
							'</span>'+
						'</p>'+
					'</div>'+
				'</div>'+
			'</a>'+
		 '</li>';

			 htmlsdata = htmlsdata +htmls;
		     }
		  	if (page == 1) {
				$('#questionsList').html(htmlsdata);
			} else {
				$('#questionsList').append(htmlsdata);
			}
		}
		function  deletquestion(id){
			
		     $("#logout").show();
		    tid = id;
			
		}
		function openPopu(i, type, data) {
			event.stopPropagation();
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
			var pTag1 = new Object();
			var pTag2 = new Object();
			var pTag3 = new Object();
			if (type == 0) {//未开始
				pTag3 = {
					imgUrl : '../../image/icon_activity_start.png',
					title : '开始'
				}
			} else if (type == 1) {//进行中
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '结束'
				}
			} else if (type == 2) {
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '已结束'
				}
			}
			/*
			 * @param topTitle标题
			 * @param pTag1标签1 不传显示默认
			 * @param pTag2标签2 不传显示默认
			 * @param pTag3标签3 不传显示默认
			 * @param imgUrl图片路径
			 * @param title标签名称
			 *  return tag 0点击背景 1点击tag1 2点击tag2 3点击tag3 4点击取消*/
			var popup = new activityBottomPopupObjc();
			popup.openBottomPopup({
				topTitle : data.name,
				pTag1 : pTag1,
				pTag2 : pTag2,
				pTag3 : pTag3
			}, function(tag) {
				//				alert(tag);
				JudgeTypeOpen(i, tag, type, data)
				popup.closeBottomPopup();
			});
		}


		function JudgeTypeOpen(i,tag, type, data) {
//			alert(tag);
			switch(tag) {
				case 1:
//				alert(data.status);
//				alert(data.status == 0);
				if(data.status == 0){
					deletquestion(data.id)
					}
					break;
				case 2:
				if(data.status==0){
					Editwin(data.id);}
					break;
				case 3:
					if (type == 0) {
						actionDosign(data.id, "start",data.name);
					} else if (type == 1) {
						actionDosign(data.id, "end",data.name);
					}
					break;
				default:
			}
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
		}
    
    
    
    
    
	
		/**
		 *签到、提问开始、结束接口
		 *
		 *uid     :用户id
		 jid     :集团id
		 iid      互动id
		 tid       互动类型id 1:签到   2：提问  3：调查  4：讨论
		 action      操作（start、<end></end>
		 ）
		 cid        课程id
		 *  */
		function actionDosign(iid, action, name) {
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				iid : iid,
				tid : 2,
				action : action,
			}
			//				alert(JSON.stringify(params));
			var actionStr = action == 'start' ? '开启' : '关闭';
			cfnetppPOST(url_actionDosign, params, true, function(data, status) {
			   if( action == 'start'){
			      SendBusinessOperationsLogNotifi('老师端提问开启', '201', params, params, '', data, '老师端提问开启接口 ', '201-01')
			   }else{
			       SendBusinessOperationsLogNotifi('老师端提问结束', '201', params, params, '', data, '老师端提问结束接口  ', '201-03')
			   }
			  
				if (status == 'success') {
					if (data.code == 200) {
						$('#questionsList').html('');
						loadNewData();
						if (action == 'start') {
							oningwin(iid, name);
						
					    }
					}else if(data.code==103){
					    ShowToast('其它终端正在使用,无法'+actionStr);
					}else{
						ShowToast(actionStr + '失败');
					}
				}else{
				    ShowToast(actionStr + '失败');
				}
			})
		}

		//取消
		function cancel() {
			$("#logout").hide();
		}

		//确定
		function confirm() {
			delet();
			$("#logout").hide();
		}

		//删除
		function delet() {
			var params = {
				aid : tid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			}
			cfnetppPOST(url_Delactive, params, true, function(data, status) {
			 SendBusinessOperationsLogNotifi('老师端提问删除', '201', params, params, '', data, '老师端提问删除接口  ', '201-02')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						$('#' + tid).remove();
						if ($('#questionsList').html() == '') {
							$('#noData').show();
							$('#noNet').hide();
							$('#mian').hide();
						}
					} else {
						ShowToast('删除失败')
					}
				} else {
					ShowToast('删除失败')
				}
			})
		}

		function openwin1(id, name, type) {
//			if (type == 1) {
//				oningwin(id, name);
//			} else if (type == 2) {
//				openwin(id, name);
//			} else if (type == 0) {
//				Editwin(id);
//			}
           getActiveStatus(id, name,type)
		}
		//获取当前提问活动状态，避免与pc状态冲突
		function getActiveStatus(id, name,type) {
		
			var params = {
				iid : id,
				source : 1,
			}
			cfnetppPOST(url_getActiveSourceConductStatus, params, false, function(data, status) {
				if (status == 'success') {
					if (data.code == 200) {
						if (type == 1) {
				           oningwin(id, name);
						} else if (type == 2) {
							openwin(id, name);
						} else if (type == 0) {
							Editwin(id);
						}
					} else {
						ShowToast(data.message)
					}
				} else {
					ShowToast(data.message)
				}
			})
		}


		function openwin(id, name) {
			api.openWin({useWKWebView:true,
				name : 'TeacherQusestionInfo',
				url : 'TeacherQusestionInfo.html',
				pageParam : {
					name : name,
					id : id,
					sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
			});
		}

		function Editwin(id) {
			api.openWin({useWKWebView:true,
				name : 'TeacherQusertion',
				url : 'TeacherQusertion.html',
				pageParam : {
					type : 2,
					id : id,
					sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
			});
		}

		//进行中
		function oningwin(id, name) {
			api.openWin({useWKWebView:true,
				name : 'TeacherQusertionNamesWind',
				url : 'TeacherQusertionNamesWind.html',
				pageParam : {
					name : name,
					id : id,
					type : 1
				},
			});
		}

</script>
</html>